package com.android.hedgehog;

import java.util.List;
import java.util.Random;

import android.graphics.Color;

import com.android.hedgehog.framework.Game;
import com.android.hedgehog.framework.Graphics;
import com.android.hedgehog.framework.Screen;
import com.android.hedgehog.framework.Input.TouchEvent;

public class FreePlayResult extends Screen {
	int score;
	int puzzleNumber;
	boolean newRecord;
	Random rand = new Random();

	public FreePlayResult(Game game) {
		super(game);

	}

	public FreePlayResult(Game game, int gameNumber, int total) {
		super(game);
		score = total;
		puzzleNumber = gameNumber;
		Settings.addScore(puzzleNumber, score);
		Settings.save(game.getFileIO());
		if (score == Settings.highScores[puzzleNumber][0] && score > Settings.highScores[puzzleNumber][1]) {
			newRecord = true;
		}
	}

	@Override
	public void update(float deltaTime) {
		Graphics g = game.getGraphics();
		List<TouchEvent> touchEvents = game.getInput().getTouchEvents();

		int len = touchEvents.size();
		for (int i = 0; i < len; i++) {
			TouchEvent event = touchEvents.get(i);
			if (event.type == TouchEvent.TOUCH_UP) {
				if (event.x > 110 && event.x < 210 && event.y > 310 && event.y < 390) {
					game.setScreen(new MainMenu2(game));
					if (Settings.soundEnabled)
						Assets.bitten.play(1);
					return;
				}
			}
		}
	}

	@Override
	public void present(float deltaTime) {
		Graphics g = game.getGraphics();
		g.drawBackground(Color.BLACK);
		g.drawUniversalText(""+score, 2, true, 160, 150, 44, 255, Color.RED);
		g.drawUniversalRect(110, 310, 100, 80, false, true, 1, 255, Color.GRAY);
		g.drawUniversalRect(110, 310, 100, 80, false, false, 5, 255, Color.DKGRAY);
		g.drawUniversalText("RETURN", 2, true, 160, 360, 20, 255, Color.WHITE);
		if (newRecord) {
			g.drawUniversalText("NEW RECORD", 2, true, 160, 460, 22, 255,
					Color.argb(255, rand.nextInt(255), rand.nextInt(255), rand.nextInt(255)));
		}
	}

	@Override
	public void pause() {
		// TODO Auto-generated method stub

	}

	@Override
	public void resume() {
		// TODO Auto-generated method stub

	}

	@Override
	public void dispose() {
		// TODO Auto-generated method stub

	}

}
